<?php

namespace App\Api\Controllers;

use App\Api\BaseController;
use App\Api\Transformers\LessonTransformer;
use App\Lesson;


class LessonsController extends BaseController
{
    // public function index() {
    //     $lessons = Lesson::all();
    //     return $this->response->collection($lessons, new LessonTransformer());
    // }

    public function index() {
        $lessons = Lesson::paginate(10);
        return $this->response->paginator($lessons, new LessonTransformer());
    }

    public function show($id) {
        // $lesson = Lesson::findOrFail($id);
        // return $this->response->item($lesson, new LessonTransformer());
        $lesson = Lesson::find($id);
        if(!$lesson) {
            return $this->response()->errorNotFound("Lesson Not Found");
        }
        return $this->response()->item($lesson, new LessonTransformer());
    }
}
